(function (vc) {
    vc.extends({
        data: {
            addAccountWithdrawalApplyInfo: {
                acctId: '',
                amount: '',
                context: '',
                accamount: '',
                objId: '',
                acctObjId: '',
                bankId: '',
                accountBanks: []
            }
        },
        _initMethod: function () {
        },
        _initEvent: function () {
            vc.on('addAccountWithdrawalApply', 'openAddAccountWithdrawalApplyModal', function (_Param) {
                $that.addAccountWithdrawalApplyInfo.acctId = _Param.acctId;
                $that.addAccountWithdrawalApplyInfo.accamount = _Param.amount;
                $that.addAccountWithdrawalApplyInfo.acctObjId = _Param.objId;
                $('#addAccountWithdrawalApplyModel').modal('show');
                $that._listAddAccountBanks();
            });
        },
        methods: {
            addAccountWithdrawalApplyValidate() {
                return vc.validate.validate({
                    addAccountWithdrawalApplyInfo: $that.addAccountWithdrawalApplyInfo
                }, {
                    'addAccountWithdrawalApplyInfo.amount': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "提现金额不能为空"
                        },
                        {
                            limit: "money",
                            param: "",
                            errInfo: "提现金额格式错误"
                        },
                    ],
                    'addAccountWithdrawalApplyInfo.bankId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "开户行不能为空"
                        }
                    ],
                    'addAccountWithdrawalApplyInfo.context': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "申请说明不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "500",
                            errInfo: "申请说明不能超过500"
                        },
                    ]
                });
            },
            _listAddAccountBanks: function () {
                let param = {
                    params: {
                        page: 1,
                        row: 50,
                        shopId: vc.getCurrentCommunity().shopId
                    }
                };
                //发送get请求
                vc.http.apiGet('/accountBank/queryAccountBank',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.addAccountWithdrawalApplyInfo.total = _json.total;
                        $that.addAccountWithdrawalApplyInfo.records = _json.records;
                        $that.addAccountWithdrawalApplyInfo.accountBanks = _json.data;
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            saveAccountWithdrawalApplyInfo: function () {
                if (!$that.addAccountWithdrawalApplyValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                if (parseFloat($that.addAccountWithdrawalApplyInfo.amount) > parseFloat($that.addAccountWithdrawalApplyInfo.accamount)) {
                    vc.toast('提现失败！账户余额不足。');
                    return;
                }
                $that.addAccountWithdrawalApplyInfo.objId = vc.getCurrentCommunity().shopId;
                vc.http.apiPost(
                    '/accountWithdrawalApply/saveAccountWithdrawalApply',
                    JSON.stringify($that.addAccountWithdrawalApplyInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#addAccountWithdrawalApplyModel').modal('hide');
                            $that.clearAddAccountWithdrawalApplyInfo();
                            vc.emit('shopAccountManage', 'listshopAccount', {});
                            vc.toast(_json.msg);
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
            clearAddAccountWithdrawalApplyInfo: function () {
                $that.addAccountWithdrawalApplyInfo = {
                    acctId: '',
                    amount: '',
                    context: '',
                    accamount: '',
                    objId: '',
                    bankId: '',
                    accountBanks: []
                };
            },
            _addAccount: function () {
                $('#addAccountWithdrawalApplyModel').modal('hide');
                vc.jumpToPage('/#/pages/goods/accountBankManage?returnFlag=1');
            },
        }
    });
})(window.vc);
